<?php

namespace app\controllers\admin\uni\system;

use app\controllers\admin\base\AdminController;
use app\models\system\SetHome as Model;

class HomeController extends AdminController
{
    public function actionFetch()
    {
        $model = Model::getLastOne();

        return $this->success($model);
    }

    public function actionSave()
    {
        $data = $this->post();

        if (!in_array($data['brand_total'], [3, 4])) {
            return $this->fail('品牌商品只能是3或者4');
        }
        if (!in_array($data['nav_total'], [4, 5])) {
            return $this->fail('导航数量只能是4或者5');
        }

        if (Model::saveData($data)) {
            return $this->success();
        }

        return $this->fail();
    }

}